package com.hs.srm.admin.modules.purchasechange.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.hs.srm.admin.modules.purchasechange.dao.PurchaseChangeRecordDao;
import com.hs.srm.admin.modules.purchasechange.entity.PurchaseChangeRecordEntity;
import com.hs.srm.admin.modules.purchasechange.service.PurchaseChangeRecordService;
import com.hs.srm.base.common.utils.QueryParam;
import com.hs.srm.common.utils.PageUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author ych
 * @since 2020-04-20 15:40:27
 */
@Service("purchaseChangeRecordService")
public class PurchaseChangeRecordServiceImpl extends ServiceImpl<PurchaseChangeRecordDao, PurchaseChangeRecordEntity> implements PurchaseChangeRecordService {

    @Resource
    private PurchaseChangeRecordDao purchaseChangeRecordDao;


    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        // 从列表页面获取对应的值
        String purchRequestCode = (String) params.get("purchRequestCode");//采购申请单号
        String purchRequestItemCode = (String) params.get("purchRequestItemCode");//行项目
        String creator = (String) params.get("creator");//申请人
        String endDate = (String) params.get("endDate");//申请日期止
        String startDate = (String) params.get("startDate");//申请日期起
        String materialCode = (String) params.get("materialCode");//采购申请单号


        Page<PurchaseChangeRecordEntity> page = this.selectPage(
                new QueryParam<PurchaseChangeRecordEntity>(params).getPage(),
                new EntityWrapper<PurchaseChangeRecordEntity>()
                        .like(StringUtils.isNotBlank(purchRequestCode), "purch_request_code", purchRequestCode)
                        .like(StringUtils.isNotBlank(creator), "creator", creator)
                        .eq(StringUtils.isNotBlank(purchRequestItemCode), "purch_request_item_code", purchRequestItemCode)
                        .eq(StringUtils.isNotBlank(materialCode), "material_code", materialCode)
                        .le(StringUtils.isNotBlank(startDate), "apply_date", startDate)
                        .ge(StringUtils.isNotBlank(endDate), "apply_date", endDate)
        );

        return new PageUtils(page);
    }
}